package com.gitee.wsl.transform.validator

import arrow.core.left
import arrow.core.nonEmptyListOf
import arrow.core.right
import com.gitee.wsl.test.shouldBe
import com.gitee.wsl.transform.validator.func.zip
import com.gitee.wsl.transform.validator.strings.minlen
import com.gitee.wsl.transform.validator.strings.notNullOrBlank
import kotlin.test.Test


class ZipTest {
   @Test
   fun test() {
      val p1 = ValidatorWithTransform.from<String?>().notNullOrBlank { "foo" }.minlen(2) { "Must have length > 2" }
      val p2 = ValidatorWithTransform.from<String?>().notNullOrBlank { "bar" }
      val p = ValidatorWithTransform.zip(p1, p2)
      p.validate(null) shouldBe nonEmptyListOf("foo", "bar").left()
      p.validate("a") shouldBe nonEmptyListOf("Must have length > 2").left()
      p.validate("ab") shouldBe Pair("ab", "ab").right()
   }

   @Test
   fun test3() {
      val p1 = ValidatorWithTransform.from<String?>().notNullOrBlank { "foo" }.minlen(2) { "Must have length > 2" }
      val p2 = ValidatorWithTransform.from<String?>().notNullOrBlank { "bar" }
      val p3 = ValidatorWithTransform.from<String?>().notNullOrBlank { "baz" }
      val p = ValidatorWithTransform.zip(p1, p2, p3)
      p.validate(null) shouldBe nonEmptyListOf("foo", "bar", "baz").left()
      p.validate("a") shouldBe nonEmptyListOf("Must have length > 2").left()
      p.validate("ab") shouldBe Triple("ab", "ab", "ab").right()
   }
}
